package com.clkj.zhonghui.controller.topic;

import com.clkj.zhonghui.pojo.common.Result;
import com.clkj.zhonghui.pojo.common.StatusCode;
import com.clkj.zhonghui.pojo.product.ProductComment;
import com.clkj.zhonghui.pojo.topic.Topic;
import com.clkj.zhonghui.service.topic.ForumService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author：周佳润
 * @Date：2024/7/18 下午2:52
 */
@RestController
@RequestMapping(value = "/forum")
@Api(value = "/forum", tags = {"论坛"})
@CrossOrigin
public class forumController {

    @Autowired
    private ForumService forumService;

    @PostMapping("/getTopicAndVideo")
    @ApiOperation(value = "初次获取文章视频列表")
    public Result getTopicAndBanner(String tagIds) {
        try {
            Map result = forumService.getTopicAndBanner(tagIds);
            return new Result(true, StatusCode.OK, "查询成功", result);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询成功", "error");
        }
    }

    @PostMapping("/getRecommend")
    @ApiOperation(value = "论坛推荐文章视频")
    public Result getRecommend(String tagIds,Integer page, Integer size) {
        try {
            PageInfo result = forumService.getRecommend(tagIds,page,size);
            return new Result(true, StatusCode.OK, "查询成功", result);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询成功", "error");
        }
    }

    @PostMapping("/getTopic")
    @ApiOperation(value = "再次获取文章列表")
    public Result getTopic(Integer page, Integer size) {
        try {
            PageInfo result = forumService.getTopic(page,size);
            return new Result(true, StatusCode.OK, "查询成功", result);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询成功", "error");
        }
    }

    @PostMapping("/getVideo")
    @ApiOperation(value = "再次获取视频列表")
    public Result getVideo(Integer page, Integer size) {
        try {
            PageInfo result = forumService.getVideo(page,size);
            return new Result(true, StatusCode.OK, "查询成功", result);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询成功", "error");
        }
    }


    @PostMapping("/getAppTopic")
    @ApiOperation(value = "app-论坛内容搜索")
    public Result getAppTopic(Integer page,Integer size,String topicTitle){
        try {
            PageInfo results = forumService.getAppTopic(page, size, topicTitle);
            return new Result(true, StatusCode.OK, "查询成功",results);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }
}
